﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 游戏平台原型
{
    public class Lobby
    {
        public Room head; //单链表的头结点
        public int no;
        static public int currentlobby;
        static public Lobby Lobby1;
        public Linklist onlinelist;

        public Lobby(int id)
        {
            no = id;
            head = null;
            onlinelist = new Linklist();
        }
        long Roomcount()
        {
            Room p = head;
            long len = 0;
            while (p != null)
            {
                ++len;
                p = p.next;
            }
            return len;
        }

        //清空单链表
        void Clear()
        {
            head = null;
        }

        //判断单链表是否为空
        bool RoomEmpty()
        {
            if (head == null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        //在单链表的末尾添加新元素
        public bool AddRoom(string newroomname, string newpassword, int newmaxperson, int newmaxpanel)
        {
            Room q = new Room(Roomcount()+1, newroomname, newpassword, User.user.currentuserno, newmaxperson, newmaxpanel);
            Room p = new Room();
            if (head == null)
            {
                head = q;
                return true;
            }
            p = head;
            while (p.next != null)
            {
                p = p.next;
            }
            p.next = q;
            return true;
        }
        //在单链表中查找值为value的结点
        public Room Seekroom(long roomid)
        {
            if (RoomEmpty())
            {
                return null;
            }
            Room p = new Room();
            p = head;
            int i = 1;
            while (p != null)
            {
                if (p.roomid == roomid)
                    break;
                p = p.next;
                ++i;
            }
            if (p == null)
                return null;
            else
                return p;
        }
        //显示链表
        /*public void DispList()
        {
            Room p = new Room();
            p = head;
            while (p != null)
            {
                Console.WriteLine("学号：\t" + p.no + " \t姓名：\t" + p.name);
                p = p.next;
            }
        }*/
    }
}
